import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../res/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// @page : ToolBar
/// @name : jhf
/// @description :公共标题栏
class ToolBar extends StatefulWidget {
  ///标题文字
  String title;

  ///右侧文字
  String endText;

  ///是否显示右侧
  bool isShowEnd = false;

  ///背景颜色
  Color backgroundColor = Colors.white;

  ///背景颜色
  Color backColor = ColorStyle.color_B8C0D4;
  Color titleColor = Colors.black87;

  VoidCallback? backOnTap;

  ToolBar({
    Key? key,
    this.title = "",
    this.endText = "",
    this.isShowEnd = false,
    this.backgroundColor = Colors.white,
    this.backOnTap,
    this.backColor = ColorStyle.color_B8C0D4,
    this.titleColor = Colors.black87,
  }) : super(key: key);

  @override
  State<ToolBar> createState() => _ToolBarState();
}

class _ToolBarState extends State<ToolBar> {
  @override
  Widget build(BuildContext context) {
    final double topPadding = MediaQuery.of(context).padding.top;

    return Container(
      color:widget.backgroundColor,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            margin:
                EdgeInsets.only(top: topPadding + 10, bottom: 6, left: 15).r,
            child: InkWell(
              borderRadius: const BorderRadius.all(
                Radius.circular(20),
              ),
              onTap: widget.backOnTap ?? () => Get.back(),
              splashColor: ColorStyle.color_E2E3E8_66,
              highlightColor: ColorStyle.color_E2E3E8_66,
              child: Container(
                margin: const EdgeInsets.all(5),
                child: Icon(
                  Icons.arrow_back_ios,
                  color: widget.backColor,
                ),
              ),
            ),
          ),
          Container(
            width: 150,
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: topPadding, right: 12),
            child: Text(
              widget.title,
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
              style:  TextStyle(color: widget.titleColor, fontSize: 16),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(15),
            child: Text(
              widget.endText,
              style: const TextStyle(
                  color: ColorStyle.color_B8C0D4, fontSize: 15),
            ),
          ),
        ],
      ),
    );
  }
}
